<!-- 
bindValue()函数方法就是讲一个值绑定到一个参数中去 
与prepare、execute函数配合使用。
-->

<?php 

try{
	$pdo = new PDO('mysql:host=localhost; dbname=exercise', 'root', 'root');
	$sql = 'insert user(username, password, email) values(?,?,?)';
	$stmt = $pdo->prepare($sql);
	$username = 'hanzhen4';
	$password = 'hanzhan5';
	$stmt->bindValue(1, $username);
	$stmt->bindValue(2, $password);
	$stmt->bindValue(3, 'hanzhen@hz.com');
	$stmt->execute();
	echo $stmt->rowCount();

	$username = 'hanzhen3';
	$password = 'hanzhan1';
	$stmt->bindValue(1, $username);
	$stmt->bindValue(2, $password);
	$stmt->execute();
	echo $stmt->rowCount();
	echo "<br/>";

	$sql1 = 'select * from user';
	//prepare($sql)； 准备一条SQl语句。
	$stmt1 = $pdo->prepare($sql1);
	//execute(); 执行一条预处理语句
	$res = $stmt1->execute();
	if($res) {
		while($row = $stmt1->fetch()) {
			echo"用户账号：";
			print_r($row['username']);
			echo"<br/>";
			echo"用户密码：";
			print_r($row['password']);
			echo"<br/>";
			echo"用户邮箱：";
			print_r($row['email']);
			echo"<br/>";
			echo"<hr/>";
		}
	}
} catch(PDOException $e) {
	echo $e->getMeassage();
}




 ?>